import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true

  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'dashboard',
        meta: { title: '消息公告', icon: 'el-icon-guide', affix: true }
      }
    ]
  },
  {
    path: '/downLoadCenter',
    component: Layout,
    redirect: '/downLoadCenter',
    children: [
      {
        path: 'downLoadCenter',
        component: () => import('@/views/downLoadCenter/index'),
        name: 'downLoadCenter',
        meta: { title: '下载中心', icon: 'el-icon-download', affix: true }
      }
    ]
  },
  {
    path: '/base',
    component: Layout,
    redirect: '/',
    name: 'base',
    meta: {
      title: '基础设置', icon: 'el-icon-setting' },
    children: [
      {
        path: 'lines',
        name: 'lines',
        component: () => import('@/views/base/index'),
        meta: { title: '线路维护', icon: 'el-icon-link' }
      },
      {
        path: 'ware',
        name: 'ware',
        component: () => import('@/views/base/ware'),
        meta: {
          title: '仓库设置', icon: 'el-icon-discount' }
      },
      {
        path: 'express',
        name: 'express',
        component: () => import('@/views/base/express'),
        meta: { title: '快递公司', icon: 'el-icon-office-building' }
      },
      {
        path: 'goods',
        name: 'goods',
        component: () => import('@/views/base/goods'),
        meta: {
          title: '商品类目', icon: 'el-icon-box' }
      },
      {
        path: 'types',
        name: 'types',
        component: () => import('@/views/base/types'),
        meta: { title: '货物类型', icon: 'el-icon-shopping-bag-2' }
      },
      {
        path: 'port',
        name: 'port',
        component: () => import('@/views/base/port'),
        meta: { title: '口岸管理', icon: 'el-icon-ship' }
      },
      {
        path: 'template',
        name: 'template',
        component: () => import('@/views/base/template'),
        meta: { title: '快递模版', icon: 'el-icon-tickets' }
      },
      {
        path: 'intercept',
        name: 'intercept',
        component: () => import('@/views/base/intercept'),
        meta: { title: '拦截列表', icon: 'el-icon-close-notification' }
      }
    ]
  },
  {
    path: '/PDA',
    component: Layout,
    redirect: '/',
    name: 'PDA',
    meta: { title: 'PDA管理', icon: 'el-icon-mobile' },
    children: [
      {
        path: 'userList',
        name: 'userList',
        component: () => import('@/views/PDA/userList'),
        meta: {
          title: '操作员', icon: 'el-icon-user'
        }
      },
      {
        path: 'web',
        name: 'web',
        component: () => import('@/views/PDA/web'),
        meta: {
          title: '网点管理', icon: 'el-icon-monitor'
        }
      },
      {
        path: 'vision',
        name: 'vision',
        component: () => import('@/views/PDA/vision'),
        meta: {
          title: '版本管理', icon: 'el-icon-upload2'
        }
      }

    ]
  },
  {
    path: '/vocational',
    component: Layout,
    redirect: '/',
    name: 'vocational',
    meta: { title: '业务设置', icon: 'el-icon-copy-document' },
    children: [
      {
        path: 'price',
        name: 'price',
        component: () => import('@/views/vocational/price'),
        meta: {
          title: '价格模版', icon: 'el-icon-coin'
        }
      },
      {
        path: 'empower',
        name: 'empower',
        component: () => import('@/views/vocational/empower'),
        meta: {
          title: '渠道授权', icon: 'el-icon-coin'
        }
      },
      {
        path: 'irrigation',
        name: 'irrigation',
        component: () => import('@/views/vocational/irrigation'),
        meta: { title: '渠道设置', icon: 'el-icon-thumb' }
      }

    ]
  },
  {
    path: '/order',
    component: Layout,
    redirect: '/',
    name: 'order',
    meta: { title: '订单管理', icon: 'el-icon-tickets' },
    children: [
      {
        path: 'allOrders',
        name: 'allOrders',
        component: () => import('@/views/order/allOrders'),
        meta: {
          title: '全部订单', icon: 'el-icon-document-copy'
        }
      },
      {
        path: 'parentList',
        name: 'parentList',
        component: () => import('@/views/order/parentList'),
        meta: {
          title: '子母件', icon: 'el-icon-document-copy'
        }
      },
      {
        path: 'childList',
        name: 'childList',
        component: () => import('@/views/order/childList'),
        hidden: true,
        meta: {
          title: '订单列表详情', icon: 'el-icon-document-copy', activeMenu: '/order/parentList'
        }
      },
      {
        path: 'batch',
        name: 'batch',
        component: () => import('@/views/order/batch'),
        meta: {
          title: '批次订单', icon: 'el-icon-document-copy'
        }
      },
      {
        path: 'batchDetail',
        name: 'batchDetail',
        component: () => import('@/views/order/batchDetail'),
        hidden: true,
        meta: {
          title: '批次订单详情', icon: 'el-icon-document-copy', activeMenu: '/order/batch'
        }
      },
      {
        path: 'changeOrder',
        name: 'changeOrder',
        component: () => import('@/views/order/changeOrder'),
        meta: {
          title: '扫描打印/换单', icon: 'el-icon-document-copy'
        }
      }
    ]
  },
  {
    path: '/lading',
    component: Layout,
    redirect: '/',
    name: 'lading',
    meta: { title: '提单管理', icon: 'el-icon-tickets' },
    children: [
      {
        path: 'ladingList',
        name: 'ladingList',
        component: () => import('@/views/lading/index'),
        meta: {
          title: '提单列表', icon: 'el-icon-tickets'
        }
      },
      {
        path: 'flight',
        name: 'flight',
        component: () => import('@/views/lading/flight'),
        meta: {
          title: '航班管理', icon: 'el-icon-water-cup'
        }
      }

    ]
  },
  {
    path: '/ware',
    component: Layout,
    redirect: '/',
    name: 'ware',
    meta: { title: '仓库管理', icon: 'el-icon-tickets' },
    children: [
      {
        path: 'package',
        name: 'package',
        component: () => import('@/views/ware/package'),
        meta: {
          title: '集包管理', icon: 'el-icon-takeaway-box'
        }
      }
    ]
  },
  {
    path: '/finance',
    component: Layout,
    redirect: '/',
    name: 'finance',
    meta: { title: '财务管理', icon: 'el-icon-document' },
    children: [
      {
        path: 'recharge',
        name: 'recharge',
        component: () => import('@/views/finance/recharge'),
        meta: {
          title: '充值审批列表', icon: 'el-icon-document-checked'
        }
      },
      {
        path: 'flow',
        name: 'flow',
        component: () => import('@/views/finance/flow'),
        meta: {
          title: '资金流水', icon: 'el-icon-coin'
        }
      },
      {
        path: 'report',
        name: 'report',
        component: () => import('@/views/finance/report'),
        meta: {
          title: '账单报表', icon: 'el-icon-tickets'
        }
      },
      {
        path: 'billAdjustment',
        name: 'billAdjustment',
        component: () => import('@/views/finance/billAdjustment'),
        meta: {
          title: '账单调整', icon: 'el-icon-brush'
        }
      },
      {
        path: 'credit',
        name: 'credit',
        component: () => import('@/views/finance/credit'),
        meta: {
          title: '账户授信', icon: 'el-icon-connection'
        }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/',
    name: 'user',
    meta: { title: '用户管理', icon: 'el-icon-user' },
    children: [
      {
        path: 'userList',
        name: 'userList',
        component: () => import('@/views/user/userList'),
        meta: {
          title: '用户列表', icon: 'el-icon-user'
        }
      }
    ]
  },
  {
    path: '/connection',
    component: Layout,
    redirect: '/',
    name: 'connection',
    meta: { title: '客户管理', icon: 'el-icon-user' },
    children: [
      {
        path: 'connectionList',
        name: 'connectionList',
        component: () => import('@/views/connection/connectionList'),
        meta: {
          title: '客户列表', icon: 'el-icon-user'
        }
      },
      {
        path: 'address',
        name: 'address',
        component: () => import('@/views/connection/address'),
        meta: {
          title: '客户地址列表', icon: 'el-icon-map-location'
        }
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    redirect: '/',
    name: 'system',
    meta: { title: '系统设置', icon: 'el-icon-setting' },
    children: [
      {
        path: 'sendAddress',
        name: 'sendAddress',
        component: () => import('@/views/system/sendAddress'),
        meta: {
          title: '发货地址', icon: 'el-icon-location-information'
        }
      }
    ]
  },
  {
    path: '/admin',
    component: Layout,
    redirect: '/',
    name: 'admin',
    meta: { title: '管理员管理', icon: 'el-icon-setting' },
    children: [
      {
        path: 'adminList',
        name: 'adminList',
        component: () => import('@/views/admin/adminList'),
        meta: {
          title: '管理员列表', icon: 'el-icon-user'
        }
      }
    ]
  }
  // {
  //   path: '/system',
  //   component: Layout,
  //   name: 'System',
  //   redirect: '/system/auth/role',
  //   meta: { title: '设置管理', icon: 'el-icon-bank-card' },
  //   children: [
  //     {
  //       path: 'auth',
  //       name: 'Auth',
  //       redirect: '/system/auth/role',
  //       component: () => import('@/views/system/auth/index'), // Parent router-view
  //       meta: { title: '权限设置', icon: 'el-icon-bank-card' },
  //       children: [
  //         {
  //           path: 'role',
  //           name: 'Role',
  //           component: () => import('@/views/system/auth/role'),
  //           meta: { title: '角色管理', icon: 'el-icon-location-information' }
  //         },
  //         {
  //           path: 'menu',
  //           name: 'Menu',
  //           component: () => import('@/views/system/auth/menu'),
  //           meta: { title: '菜单管理', icon: 'el-icon-location-information' }
  //         }

  //       ]
  //     }
  //   ]
  // }

]

// TODO: 迁到项目 https://gitee.com/linkurl/stormVueAdmin
// 控制台
// 设置
// 用户管理

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter(newConstantRoutes) {
  const newCreateRouter = () => new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: newConstantRoutes
  })
  const newRouter = newCreateRouter()
  router.matcher = newRouter.matcher // reset router
  console.log(router)
}

export default router
